//
//  BKXEmotionPageView.swift
//  微博
//
//  Created by 田凯 on 16/4/25.
//  Copyright © 2016年 田凯. All rights reserved.
//

import UIKit
//  cellID
let BKXEmotionPageViewId = "BKXEmotionPageViewId"


class BKXEmotionPageView: UICollectionView {
    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        super.init(frame: frame, collectionViewLayout: UICollectionViewFlowLayout())
        setupUI()
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
   
    // 设置 视图
   private func setupUI(){
    
    self.backgroundColor = RandomColor()
        dataSource = self
    // 注册cell 
    registerClass(BKXEmotionPageViewCell.self, forCellWithReuseIdentifier: BKXEmotionPageViewId)
    
    //获取layout
     let layout = collectionViewLayout as! UICollectionViewFlowLayout
    
    // 设置 itemSize
    layout.itemSize = CGSize(width: ScreenW, height: 216 - 37)
    //设置 水平垂直间距
    layout.minimumLineSpacing = 0
    layout.minimumInteritemSpacing = 0
    //设置 滚动方向
    layout.scrollDirection = .Horizontal
    
    }
    

}
extension BKXEmotionPageView :UICollectionViewDataSource{

    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        return BKXEmotionTools.sharedTools.allEmotions.count
    }
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return BKXEmotionTools.sharedTools.allEmotions[section].count
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(BKXEmotionPageViewId, forIndexPath: indexPath) as! BKXEmotionPageViewCell
//        cell.backgroundColor = RandomColor()
        
        cell.indexPath = indexPath
        return cell
        
    }
}
